#!/bin/bash

#pwrap="$HOME/scripts/common/pwwrap"
sync="/usr/bin/rsync -vazuP --progress --del"

logf="/dev/null"
function log(){
  log_file="`basename $0`@`hostname`.log"
  for log_dir in /var/log "$HOME" . /tmp /dev/null
  do
    [ -w "$log_dir" ] && touch "$log_dir/$log_file" && break
  done
  log_url="$log_dir/$log_file"
  [ ! -w "$log_url" ] && return
  logf="$log_url"

  log_msg="$1"
  [ "$1" == "time" ] && log_msg="[`date +'%Y/%m/%d %H:%M:%S'`]: $2"
  echo "$log_msg" >> "$log_url"
  echo "$log_msg"
  return
}

if [ "`hostname`" == "lanagt" ]
then
  log "time" "sync baiduyun from lanagt to lanxpc ......"
  $sync -e ssh /pbfd/share/baiduyun root@lanxpc:/pbfd/share
  log "time" "done"
fi

if [ "`hostname`" == "lanads" ]
then
  log "time" "sync AD files from linuxqa to lanads ......"
  $sync -e ssh dahai@linuxqa.chn.hp.com:/pbfd/share/lance/AD /pbfd/incoming
  log "time" "done"
fi

